package com.gy.bearhelps.setting;

import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gy.bearhelps.R;
import com.gy.bearhelps.base.BaseActivity;
import com.gy.bearhelps.util.AnimUtil;
import com.gy.bearhelps.util.DataCleanManager;
import com.gy.bearhelps.util.SharedPrefUtil;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * 作者：gy on 16/11/5
 * 说明：设置
 */
public class SettingMainActivity extends BaseActivity {

    public static int SETTING_FONT = 101;
    private LinearLayout llFont,llMessage,llFile,llMemory,llVersion,llHelp;
    private TextView tvFont,tvMemory,tvVersion;
    private String strFont,size;

    @Override
    protected void initView() {
        setContentViewRes(R.layout.activity_setting_main);
        setTitleMsg("设置");
        llFont = (LinearLayout) findViewById(R.id.activity_set_ll_font);
        llMessage = (LinearLayout) findViewById(R.id.activity_set_ll_message);
        llFile = (LinearLayout) findViewById(R.id.activity_set_ll_file);
        llMemory = (LinearLayout) findViewById(R.id.activity_set_ll_memory);
        llVersion = (LinearLayout) findViewById(R.id.activity_set_ll_version);
        llHelp = (LinearLayout) findViewById(R.id.activity_set_ll_help);
        tvFont = (TextView) findViewById(R.id.activity_set_tv_font);
        tvMemory = (TextView) findViewById(R.id.activity_set_tv_memory);
        tvVersion = (TextView) findViewById(R.id.activity_set_tv_version);
    }

    @Override
    protected void initData() {
        strFont = SharedPrefUtil.get("font","");
        try {
            size = DataCleanManager.getTotalCacheSize(this);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void setListener() {
        super.setListener();
        llFont.setOnClickListener(this);
        llMessage.setOnClickListener(this);
        llFile.setOnClickListener(this);
        llMemory.setOnClickListener(this);
        llVersion.setOnClickListener(this);
        llHelp.setOnClickListener(this);
    }

    @Override
    protected void fillData() {
        super.fillData();
        tvFont.setText(strFont);
        tvMemory.setText(size+"");
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        Intent intent;
        switch (v.getId()){
            case R.id.activity_set_ll_font:
                intent = new Intent(this,SetFontActivity.class);
                startActivityForResult(intent,SETTING_FONT);
                AnimUtil.pushLeftInAndOut(this);
                break;
            case R.id.activity_set_ll_memory:
                showLoadDialog("正在清理");
                ImageLoader.getInstance().clearDiskCache();
                ImageLoader.getInstance().clearMemoryCache();
                DataCleanManager.clearAllCache(this);
                String size2 = "";

                try {
                    size2 = DataCleanManager.getTotalCacheSize(this);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                if("0K".equals(size2)){
                    tvMemory.setText(size2+"");
                    closeLoadDialog();
                    showToast("清理成功");
                }
                break;
            case R.id.activity_set_ll_message:
                intent = new Intent(this,MessageListActivity.class);
                startActivity(intent);
                AnimUtil.pushLeftInAndOut(this);
                break;
            case R.id.activity_set_ll_file:
                intent = new Intent(this,DownFileActivity.class);
                startActivity(intent);
                AnimUtil.pushLeftInAndOut(this);
                break;
            case R.id.activity_set_ll_version:

                break;
            case R.id.activity_set_ll_help:
                intent = new Intent(this,HelpActivity.class);
                startActivity(intent);
                AnimUtil.pushLeftInAndOut(this);
                break;
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode == SETTING_FONT){
            strFont = data.getStringExtra("font");
            tvFont.setText(strFont);
            SharedPrefUtil.put("font",strFont);
        }
    }
}
